package 
{
	import laya.d3.resource.models.SphereMesh;
	import laya.d3.core.MeshSprite3D;
	import laya.d3.core.Sprite3D;
	import common.TargetMoveScript;
	import laya.d3.component.physics.MeshCollider;
	import laya.d3.component.Rigidbody;
	import laya.d3.component.physics.BoxCollider;
	import laya.d3.component.physics.SphereCollider;
	import laya.d3.resource.models.PrimitiveMesh;

	/**
	 * ...
	 * @author
	 */
	public class Target extends Sprite3D{
		private static var pool:Array = [];
		//圆形
		public static const TYPE_1:int = 1;
		public static const TYPE_2:int = 2;
		public static const TYPE_3:int = 3;

		//静止
		public static const MOVE_TYPE_1:int = 1;
		//横向运动
		public static const MOVE_TYPE_2:int = 2;
		public static const MOVE_TYPE_3:int = 3;
		private var scoreInfo:Array = [
			[1,2,2],
			[1,2,2],
			[1,2,2]
		];

		public var type:int;
		public var score:int;
		private var targetMoveScript:TargetMoveScript;
		public function Target(){
			
		}

		/**
		 * 目标类型，移动类型
		 */
		public function create(type:int = Target.TYPE_1,moveType:int = Target.MOVE_TYPE_1):void
		{
			this.type = type;
			if(type == TYPE_1)
			{
				//创建球体模型(参数为：半径、水平层数、垂直层数)
            	var sphereMesh:SphereMesh = new SphereMesh(0.5,16,16);
				//创建模型显示对象
            	var sphere3D:MeshSprite3D=new MeshSprite3D(sphereMesh);
				this.addChild(sphere3D);

				var collider:SphereCollider = this.addComponent(SphereCollider) as SphereCollider;
				collider.center = sphereMesh.boundingSphere.center.clone();
				collider.radius = sphereMesh.boundingSphere.radius;
			}
			else if(type == TYPE_2)
			{

			}
			targetMoveScript = this.addComponent(TargetMoveScript) as TargetMoveScript;
			targetMoveScript.setMoveType(moveType);
			score = scoreInfo[type-1][moveType-1];
		}

		public function set isPause(value:Boolean):void
		{
			targetMoveScript.isPause = value;
		}

		public static function createTarget(type:int = TYPE_1,moveType:int = MOVE_TYPE_1):Target
		{
			var target:Target;
			if(pool.length > 0)
			{
				target = pool.shift();
			}
			else
			{
				target = new Target();
			}
			target.create(type,moveType);
			return target;
		}

		public static function returnTarget(target:Target):void
		{
			if(pool.indexOf(target) == -1)
			{
				pool.push(target);
			}
		}
	}

}